
//当某个客户端的tcp连接断开的处理 不彻底清除数据 而是等待客户端重连
// @ts-ignore
await execute();
async function execute() {
    G.EventCallback.publish_event("断开连接",[]);
    let client_id = ClientUtils.get_client_id();
    let username = _ClientUserNameData.get(client_id);
    let ids = _UserNameCidsData.get(username);
    if (ids !== undefined) {
        for (let index = 0; index < ids.length; index++) {
            let id = ids[index];
            let characters = _CharactersData.get(id);
            let offline_time = Math.floor(Date.now() / 1000);
            //组队中处理
            characters["离线时间"] = offline_time;
            if(characters["队伍"] !== 0  && _TeamDataCache.has(characters["队伍"])){
                G.TeamUtils.send_team_message(characters["队伍"],`成员#Y[${characters["名称"]}]#R掉线(网络中断)`);
            }
            // TODO 战斗中离线 则设置自动战斗
            if (characters["战斗开关"] !== 0) {
                let fight_data = _FightDataCache.get(characters["战斗开关"]);
                if (fight_data) {
                     let fight_unit = G.FightUtils.get_fight_unit_by_characters(fight_data, characters);
                     fight_unit["自动战斗"] = true;
                }
            }
            // 持久化角色数据
            // @ts-ignore
            await G.Characters.update_characters_data_by_json_data(characters);
        }
    }
}